package app.xx.marquee.text

import android.os.Bundle
import android.text.Editable
import android.text.TextWatcher
import android.view.View
import android.view.Window
import android.view.WindowManager
import androidx.appcompat.app.AppCompatActivity
import com.xx.marqueetext.databinding.ActivityMainBinding


class MainActivity : AppCompatActivity() {
    private lateinit var binding: ActivityMainBinding
    var ishint = false;
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        // 隐藏标题栏
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        // 隐藏状态栏
        window.setFlags(
            WindowManager.LayoutParams.FLAG_FULLSCREEN,
            WindowManager.LayoutParams.FLAG_FULLSCREEN
        );

        binding = ActivityMainBinding.inflate(layoutInflater)
        setContentView(binding.root)

        binding.editText.addTextChangedListener(object : TextWatcher {
            override fun beforeTextChanged(s: CharSequence?, start: Int, count: Int, after: Int) {
            }

            override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) {
                binding.marqueeText.text = s
            }

            override fun afterTextChanged(s: Editable?) {

            }
        })

        binding.hintView.setOnClickListener {
            ishint = !ishint
            hintBtnView(ishint)
        }
    }

    private fun hintBtnView(isHint: Boolean) {
        if (isHint) {
            binding.llBtnLayout.visibility = View.GONE
            binding.editText.visibility = View.GONE
        } else {
            binding.editText.visibility = View.VISIBLE
            binding.llBtnLayout.visibility = View.VISIBLE
        }
    }

    fun start(v: View?) {
        binding.marqueeText.startScroll() // 开始滚动
        ishint = true
        hintBtnView(ishint)
    }

    fun stop(v: View?) {
        binding.marqueeText.stopScroll() // 停止滚动
    }

    fun startFor0(v: View?) {
        binding.marqueeText.startFor0() // 从新开始滚动
    }

    fun left(v: View?) {//想做滚动
        binding.marqueeText.left()
    }

    fun right(v: View?) {//向右滚动
        binding.marqueeText.right()
    }

    fun addSpeed(v: View?) {//加速
        binding.marqueeText.addSpeed()
    }

    fun reduceSpeed(v: View?) {//减速
        binding.marqueeText.reduceSpeed()
    }
}